import os
from abc import ABC

from app.configs import global_config
from app.views import CommonHandler
from app.models.cod import Error


class DumpHandler(CommonHandler, ABC):
    async def get(self):
        if not os.path.exists(global_config['db']):
            await self.response(error=Error.NotDump)
            return

        with open(global_config['db'], 'rb') as f:
            content = f.read()
            self.write(content)

        await self.finish()
